package com.ceres.system.service.impl;

import com.ceres.system.dao.UserMapper;
import com.ceres.system.pojo.Customer;
import com.ceres.system.pojo.User;
import com.ceres.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SystemServiceImpl implements SystemService {

    @Autowired
    private UserMapper userMapper;
    /**
     * 通过农业组织id查询农业组织
     * @param username
     * @return
     */
    @Override
    public Customer findCust(String username) {
        //先通过username查询登录人所属的农业组织的id
        User user = userMapper.findUserByUserName(username);
        Integer customerId = user.getCustomerId();
        //在通过农业组织id查询农业组织
        return userMapper.findCustomerById(customerId);
    }

    /**
     * 更改主题
     * @param username
     * @param theme
     */
    @Override
    public void changeTheme(String username,String theme) {
        User user = userMapper.findUserByUserName(username);
        Integer userId = user.getId();
        userMapper.changeTheme(theme,userId);
    }

    /**
     * 修改logo
     * @param username
     * @param logo
     */
    @Override
    public void updateLogo(String username, String logo) {
        User user = userMapper.findUserByUserName(username);
        Integer userId = user.getId();
        userMapper.updateLogo(username,logo);
    }

    /**
     * 修改项目名称
     * @param username
     * @param ProjectName
     */
    @Override
    public void updateProjectName(String username, String ProjectName) {
        User user = userMapper.findUserByUserName(username);
        Integer userId = user.getId();
        userMapper.updateProjectName(username,ProjectName);
    }

}
